<template>
  <el-row :gutter="40" class="panel-group">
    <el-col :xs="24" :sm="24" :lg="24" class="card-panel-col">
      <div class="sigma-content">
        <div class="sigma-middle-line">
          <div class="sigma-line-text">
            <el-button
              :type="tip == false ? 'primary' : ''"
              style="width:100px;border-radius:2px;"
              @click="today()"
              >今日</el-button
            >
            <el-button
              :type="tip == true ? 'primary' : ''"
              style="width:100px;border-radius:2px;"
              @click="yesterday()"
              >昨日</el-button
            >
            <div style="float:right;">
              <el-date-picker
                v-model="times"
                class="filter-item"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width: 250px;"
                type="daterange"
                value-format="yyyy-MM-dd"
              />
              <el-button
                class="filter-item"
                style="margin-left: 10px;width:110px;border-radius:4px;"
                type="danger"
                @click="handleQuery()"
              >
                查询
              </el-button>
            </div>
          </div>
        </div>
      </div>
    </el-col>

    <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div
        class="card-panel"
        style="border-bottom: 8px solid #268AF0;"
        @click="handleSetLineChartData('newVisitis')"
      >
        <div class="card-panel-description">
          <div class="card-panel-text">
            注册数
            <el-popover
              placement="top"
              width="200"
              trigger="hover"
              content="H5注册总人数(易薪+融e多)"
            >
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <count-to
            :start-val="0"
            :end-val="resData.regCount"
            :duration="2600"
            class="card-panel-num"
          />
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div
        class="card-panel"
        style="border-bottom: 8px solid #1BD0FD;"
        @click="handleSetLineChartData('messages')"
      >
        <div class="card-panel-description">
          <div class="card-panel-text">
            完件数
            <el-popover
              placement="top"
              width="200"
              trigger="hover"
              content="用户填写完整表单的人数(易薪+融e多)"
            >
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <count-to
            :start-val="0"
            :end-val="resData.completeCount"
            :duration="3000"
            class="card-panel-num"
          />
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div
        class="card-panel"
        style="border-bottom: 8px solid #FED54E;"
        @click="handleSetLineChartData('purchases')"
      >
        <div class="card-panel-description">
          <div class="card-panel-text">
            进件成功数
            <el-popover
              placement="top"
              width="200"
              trigger="hover"
              content="用户填写表单并推送成功的数量(易薪+融e多)"
            >
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <count-to
            :start-val="0"
            :end-val="resData.entryCount"
            :duration="3200"
            class="card-panel-num"
          />
        </div>
      </div>
    </el-col>
    <!-- <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div class="card-panel" style="border-bottom: 8px solid #2CDAB5;" @click="handleSetLineChartData('shoppings')">
        <div class="card-panel-description">
          <div class="card-panel-text">
            登录数
            <el-popover
                placement="top"
                width="200"
                trigger="hover"
                content="当天注册用户登录APP的次数，每个用户算一个（单独易薪）"
              >
                <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <count-to :start-val="0" :end-val="resData.loginCount" :duration="3600" class="card-panel-num" />
        </div>
      </div>
    </el-col> -->
    <!-- <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div class="card-panel" style="border-bottom: 8px solid #CC99FF;" @click="handleSetLineChartData('shoppings')">
        <div class="card-panel-description">
          <div class="card-panel-text">
            认证数
            <el-popover
                placement="top"
                width="200"
                trigger="hover"
                content="在APP中完成认证流程的人数（单独易薪）"
              >
                <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <count-to :start-val="0" :end-val="resData.authCount" :duration="3600" class="card-panel-num" />
        </div>
      </div>
    </el-col> -->

    <!-- 第二排四个统计 -->
    <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div
        class="card-panel"
        style="border-bottom: 8px solid #1BD0FD;"
        @click="handleSetLineChartData('newVisitis')"
      >
        <div class="card-panel-description">
          <div class="card-panel-text">
            注册率
            <el-popover
              placement="top"
              width="200"
              trigger="hover"
              content="注册数/UV数"
            >
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <span class="card-panel-num">{{ resData.registerRate }}</span>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div
        class="card-panel"
        style="border-bottom: 8px solid #2CDAB5;"
        @click="handleSetLineChartData('messages')"
      >
        <div class="card-panel-description">
          <div class="card-panel-text">
            完件率
            <el-popover
              placement="top"
              width="200"
              trigger="hover"
              content="用户填写完整表单的人数/注册数"
            >
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <span class="card-panel-num">{{ resData.completeCountRate }}</span>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div
        class="card-panel"
        style="border-bottom: 8px solid #268AF0;"
        @click="handleSetLineChartData('purchases')"
      >
        <div class="card-panel-description">
          <div class="card-panel-text">
            进件率
            <el-popover
              placement="top"
              width="200"
              trigger="hover"
              content="成功进件的数量/用户填写表单并推送的数量"
            >
              <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <span class="card-panel-num">{{ resData.entrySuccessRate }}</span>
        </div>
      </div>
    </el-col>
    <!-- <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div class="card-panel" style="border-bottom: 8px solid #FED54E;" @click="handleSetLineChartData('shoppings')">
        <div class="card-panel-description">
          <div class="card-panel-text">
            登录率
             <el-popover
                placement="top"
                width="200"
                trigger="hover"
                content="登录数/注册数"
              >
                <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <span class="card-panel-num">{{ resData.numberOfLoginRate }}</span>
        </div>
      </div>
    </el-col>
     <el-col :xs="12" :sm="6" :lg="4" class="card-panel-col">
      <div class="card-panel" style="border-bottom: 8px solid #CC99FF;" @click="handleSetLineChartData('shoppings')">
        <div class="card-panel-description">
          <div class="card-panel-text">
            认证率
             <el-popover
                placement="top"
                width="200"
                trigger="hover"
                content="在APP中完成认证流程的人数/注册数"
              >
                <i class="el-icon-info" slot="reference"></i>
            </el-popover>
          </div>
          <span class="card-panel-num">{{ resData.numberOfPeopleRate }}</span>
        </div>
      </div>
    </el-col> -->

    <!-- <el-col :span="24" class="card-panel-col">
      <div class="card-panel" style="height:58px">
        <table>
          <tr>
            <td><div class="info-name">设备注册量(台)</div></td>
            <td><div class="info">{{ f2.deviceCount }}</div></td>
            <td><div class="card-panel-text info-name ">短信余额（RMB）</div></td>
            <td><div class="info">{{ f2.smsBalance }}</div></td>
          </tr>
        </table>
      </div>
    </el-col> -->
  </el-row>
</template>

<script>
import CountTo from 'vue-count-to';
import {
  getUserPeriodDayStatistics,
  getDeviceCount,
  getTodayDeviceCount
} from '@/api/home';
export default {
  components: {
    CountTo
  },
  data() {
    return {
      listQuery: {
        queryType: 'today',
        current: 1,
        size: 10,
        phone: ''
      },
      times: [],
      resData: {
        regCount: 0,
        authCount: 0,
        vipCount: 0,
        completeCount: 0,
        entryCount: 0,
        numberOfSuccessfulWithdrawals: 0,
        numberOfLoginRate: 0,
        numberOfPeopleRate: 0,
        numberOfRegisteredRate: 0,
        numberOfNextPaymentRate: 0,
        vipReportResult: {
          vipIncome: 0,
          numberOfCurrentTransactionsInitiated: 0,
          numberOfSuccessfulRecords: 0,
          numberOfFailedRecords: 0,
          flowSuccessRate: 0,
          totalRefundNum: 0
        },
        loanAssistanceProducts: {
          passingNumberOfFrontScreen: 0,
          numberOfPasses: 0,
          numberOfFormsSubmittedSuccessfully: 0,
          creditSuccess: 0,
          overCounting: 0,
          numberOfLoansApproved: 0,
          numberOfSuccessfulLoans: 0,
          numberOfSuccessfulRepayment: 0,
          passingRateOfFrontScreen: 0,
          accessRate: 0,
          creditSuccessRate: 0,
          passRateOfCardBinding: 0,
          loanApprovalRate: 0,
          loanSuccessRate: 0
        }
      },
      tip: false,
      countT: 0,
      inT: {}
    };
  },
  created() {
    // this.inT = window.setInterval(() => {
    //   if (this.countT >= 50000) {
    //     this.countT = 50000
    //     window.clearInterval(this.inT)
    //   } else if (this.countT < 100) {
    //     this.countT += 1
    //   } else if (this.countT < 1000) {
    //     this.countT += 11
    //   } else if (this.countT < 10000) {
    //     this.countT += 111
    //   } else if (this.countT < 40000) {
    //     this.countT += 1111
    //   } else if (this.countT < 49000) {
    //     this.countT += 111
    //   } else if (this.countT < 49900) {
    //     this.countT += 11
    //   } else if (this.countT <= 50000) {
    //     this.countT += 1
    //   }
    // }, 5)

    this.getUserPeriodDayStatistics();
  },
  methods: {
    handleQuery() {
      this.listQuery.queryType = 'sectionDate';
      if (this.times == null) {
        this.listQuery.endDate = '';
        this.listQuery.startDate = '';
      } else if (this.times.length === 0) {
        this.listQuery.endDate = '';
        this.listQuery.startDate = '';
      } else {
        this.listQuery.endDate = this.times[1];
        this.listQuery.startDate = this.times[0];
      }
      this.getUserPeriodDayStatistics();
    },
    today() {
      this.listQuery.queryType = 'today';
      this.tip = false;
      this.getUserPeriodDayStatistics();
    },
    yesterday() {
      this.listQuery.queryType = 'yesterday';
      this.tip = true;
      this.getUserPeriodDayStatistics();
    },
    // 搜索
    async getUserPeriodDayStatistics() {
      const res = await getUserPeriodDayStatistics(this.listQuery);
      if (res.data.code === 200) {
        this.resData = res.data.data.data;
      } else {
        this.$notify({
          title: '失败',
          message: '获取数据失败',
          type: 'success',
          duration: 2000
        });
      }
    },
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type);
    },

    // 设备注册量
    async getDeviceCount(listQuery) {
      const res = await getDeviceCount(this.listQuery);
      // console.log(res)
      this.f2 = res.data.data;
    },
    async getTodayDeviceCount(listQuery) {
      const res = await getTodayDeviceCount(this.listQuery);
      // console.log(res)
      this.f2 = res.data.data;
    }
  }
};
</script>

<style lang="scss" scoped>
.info {
  text-align: left;
  margin-left: 90px;
  margin-top: 10px;
  font-weight: 500;
  font-size: 30px;
}
.info-name {
  text-align: left;
  margin-left: 50px;
  margin-top: 10px;
  color: rgb(172, 176, 177);
  line-height: 18px;
  color: rgba(0, 0, 0, 0.45);
  font-size: 16px;
  margin-bottom: 12px;
}
.panel-group {
  margin: 18px -5px !important;

  .card-panel-col {
    padding-right: 5px !important;
    padding-left: 5px !important;
    margin-bottom: 22px;
  }

  .card-panel {
    border-radius: 8px;
    height: 108px;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-description {
      // float: right;
      text-align: center;
      font-weight: bold;
      margin: 26px;

      .card-panel-text {
        line-height: 18px;
        color: #354768;
        font-size: 18px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 36px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
.vip-p {
  text-align: left;
  color: #354768;
  font-size: 16px;
  padding: 5px 0;
}
.vip-title {
  color: #8f97a7;
}
.vip-title::before {
  content: '';
  display: inline-block;
  vertical-align: 3px;
  margin-right: 10px;
  background: #167bff;
  width: 6px;
  height: 6px;
  border-radius: 3px;
}
.sigma-content {
  background-color: #ffffff;
  border-radius: 8px;
  height: 78px;
  line-height: 78px;
}
.sigma-line-text {
  width: 100%;
  display: inline-block;
  padding: 0 18px 0 18px;
  position: relative;
  font-size: 14px;
  font-weight: 500;
}
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}
</style>
